<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>系统设置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        .layui-form-item .layui-input-company {
            width: auto;
            padding-right: 10px;
            line-height: 38px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">网站名称</label>
                <div class="layui-input-block">
                    <input type="text" id="sitename" name="sitename" lay-verify="required"
                           lay-reqtext="网站域名不能为空"
                           placeholder="请输入网站名称" value="layuimini" class="layui-input">
                    <tip>填写自己部署网站的名称。</tip>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">logo标题</label>
                <div class="layui-input-block">
                    <input type="text" id="logoTitle" name="logoTitle" lay-verify="required"
                           lay-reqtext="logo标题不能为空"
                           placeholder="请输入logo标题" value="layuimini" class="layui-input">
                    <tip>logo标题。</tip>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">logo图片</label>
                <div class="layui-input-block">
                    <img src="../images/logo.png" width="50" id="logo" style="cursor: pointer">
                    <tip>点击上传logo图片。</tip>
                    <input type="text" class="layui-hide" name="logoImage" id="logoImage">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">网站域名</label>
                <div class="layui-input-block">
                    <input type="text" id="domain" name="domain" lay-verify="required" lay-reqtext="网站域名不能为空"
                           placeholder="请输入网站域名" value="http://layuimini.99php.cn" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">缓存时间</label>
                <div class="layui-input-inline" style="width: 80px;">
                    <input type="text" id="cache-time" name="cacheTime" lay-verify="number" value="0"
                           class="layui-input">
                </div>
                <div class="layui-input-inline layui-input-company">分钟</div>
                <div class="layui-form-mid layui-word-aux">本地开发一般推荐设置为 0，线上环境建议设置为 10。</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">最大文件上传</label>
                <div class="layui-input-inline" style="width: 80px;">
                    <input type="text" id="max-file-upload" name="maxFileUpload" lay-verify="number" value="2048"
                           class="layui-input">
                </div>
                <div class="layui-input-inline layui-input-company">KB</div>
                <div class="layui-form-mid layui-word-aux">提示：1 M = 1024 KB</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">上传文件类型</label>
                <div class="layui-input-block">
                    <input type="text" id="file-upload-ext" name="fileUploadExt" value="png|gif|jpg|jpeg|zip|rar"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label required">首页标题</label>
                <div class="layui-input-block">
                    <textarea name="homePageTitle" id="home-page-title"
                              class="layui-textarea">layuimini 简洁易用后台管理模板</textarea>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label required">首页url</label>
                <div class="layui-input-block">
                    <input name="homePageHref" readonly id="home-page-href" lay-verify="required"
                           lay-reqtext="首页url不能为空"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">META关键词</label>
                <div class="layui-input-block">
                    <textarea id="meta-keywords" name="metaKeywords" class="layui-textarea"
                              placeholder="多个关键词用英文状态 , 号分割"></textarea>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">META描述</label>
                <div class="layui-input-block">
                    <textarea id="meta-description" name="metaDescription"
                              class="layui-textarea">layuimini，最简洁、清爽、易用的layui后台框架模板。</textarea>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label required">版权信息</label>
                <div class="layui-input-block">
                    <textarea id="copyright" name="copyright" class="layui-textarea">© 2019 layuimini.99php.cn MIT license</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="setting">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../js/ajax-common.js" charset="UTF-8"></script>
<script>
    layui.use(['form', 'upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , upload = layui.upload;

        var uploadInst = upload.render({
            elem: '#logo' //绑定元素
            , url: '/api/file/upload' // 上传接口，实际使用时改成您自己的上传接口即可。
            , accept: 'images'
            , data: {
                avatar: true
            }
            , done: function (res) {
                //上传完毕回调
                if (res.code === 0) {
                    layer.msg('上传完成', {icon: 1});
                    $("#logo").attr('src', "/" + res.data.fileName);
                    $("#logoImage").val("/" + res.data.fileName);
                } else {
                    layer.msg('上传失败,msg=' + res.msg, {icon: 5})
                }
            }
            , error: function () {
                //请求异常回调
                layer.msg('上传失败', {icon: 5})
            }
        });

        get("/api/base/siteinfo", function (data) {
            $("#sitename").val(data.sitename);
            $("#logoTitle").val(data.logoTitle);
            $("#domain").val(data.domain);
            $("#cache-time").val(data.cacheTime);
            $("#max-file-upload").val(data.maxFileUpload);
            $("#file-upload-ext").val(data.fileUploadExt);
            $("#home-page-title").val(data.homePageTitle);
            $("#meta-keywords").val(data.metaKeywords);
            $("#meta-description").val(data.metaDescription);
            $("#copyright").val(data.copyright);
            $("#home-page-href").val(data.homePageHref);
            $("#logoImage").val(data.logoImage);
            $("#logo").attr("src", data.logoImage);

        })

        //监听提交
        form.on('submit(setting)', function (data) {

            post("/api/base/update-siteinfo", data.field, (res) => {
                layer.msg("操作成功", {icon: 1})
            })
            return false;
        });

    });
</script>
</body>
</html>